package com.oa.organization.controller;

import com.oa.oaspccommon.po.Dept;
import com.oa.organization.service.DeptService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zd
 * @date 2021年04月16日 9:02
 */
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;


    /**
     * 查询公司下的部门
     * @return
     */
    @RequestMapping(value = "/deptes",method = RequestMethod.GET)
    public List<Dept> findDeptByCompany(){
        return deptService.findDeptByCompany();
    }

    /**
     * 根据部门id查询所有子部门
     * @param deptno
     * @return
     */
    @RequestMapping(value = "/depts",method = RequestMethod.GET)
    public List<Dept> findDepts(@RequestParam("deptno") Integer deptno){
        return deptService.findDepts(deptno);
    }

    /**
     * 根据deptid查询dept
     * @param deptid
     * @return
     */
    @RequestMapping(value = "/dept",method = RequestMethod.GET)
    public Dept findOne(@RequestParam("deptid") Integer deptid){
        return deptService.findByDeptid(deptid);
    }

    /**
     * 添加dept
     * @param dept
     * @return
     */
    @RequestMapping(value = "/dept",method = RequestMethod.POST)
    public Boolean addDept(@RequestBody Dept dept){
        int i = deptService.addDept(dept);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
     * 删除
     * @param deptid
     * @return
     */
    @RequestMapping(value = "/dept",method = RequestMethod.DELETE)
    public Boolean delDept(@RequestParam("deptid")Integer deptid){
        int i = deptService.delDept(deptid);
        if(i>0){
            return true;
        }
        return false;
    }


    /**
     * 修改
     * @param dept
     * @return
     */
    @RequestMapping(value = "/dept",method = RequestMethod.PUT)
    public Boolean updateDept(@RequestBody Dept dept){
        int i = deptService.updateDept(dept);
        if(i>0){
            return true;
        }
        return false;
    }
}
